﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace BPM.Base.WFLib.GuideForm
{
    public partial class assign : incept
	{
		public assign()
		{
			InitializeComponent();
		}
        public assign(WaitSubmitDesigner designer)
            : base(designer)
        {
            InitializeComponent();

            this.分配部门.Text=activity.分配部门  ;
            this.分配职能.Text=activity.分配职能  ;
            分配时限.Text = activity.分配时限.ToString();


            string[] tps = activity.分配时特殊权限.Split(',');

            foreach (var tp in tps)
            {
                for (int i = 0; i <= this.分配时特殊权限.Items.Count - 1; i++)
                {
                    if (this.分配时特殊权限.Items[i].ToString() == tp)
                    {
                        this.分配时特殊权限.SetItemChecked(i, true);
                    }
                }
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            DepartmentDutyForm dForm = new DepartmentDutyForm();
            dForm.ShowDialog();
            if (dForm.Value != null)
            {
                if (dForm.Value.IndexOf("|") != -1)
                {
                    Button bt = sender as Button;



                    string[] department = dForm.Value.Split('|')[0].Split(',');
                    string[] duty = dForm.Value.Split('|')[1].Split(',');

                    this.分配部门.Text = department[0];
                    this.分配职能.Text = duty[0];


                }
            }
        }

        public void setAssign()
        {

            activity.分配部门 = this.分配部门.Text;
            activity.分配职能 = this.分配职能.Text;

            //分配时限
            int n;
            if (int.TryParse(this.分配时限.Text, out n))
            {
                activity.分配时限 = n;
            }
            else
            {
                分配时限.Text = activity.分配时限.ToString();
            }

            //分配时特殊权限
            string tp = "";

            foreach (var v in this.分配时特殊权限.CheckedItems)
            {
                tp = tp + v.ToString() + ",";
            }
            if (tp != "")
            {
                activity.分配时特殊权限 = tp.Remove(tp.Length - 1);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
 

            this.setTransact();
            setIncept();
            setAssign();
            activity.处理方式 = "组分配";
            this.Close();
        }
	}
}
